<template>
  <div id="PickDetail">
    <v-details :inputConfig="inputConfig"
               :detailData="inputData"
               :rules="rules"
               @pop="setdata"
               ref="input"></v-details>
  </div>
</template>

<script>
import details from 'commons/Detail'
import baseMixin from "@/mixins/BaseMixin";

export default {
  props: {
    inputData: {
      type: Object,
    }
  },
  mixins: [baseMixin],
  name: "PickDetail",
  data () {
    return {
      rules: {
        storerkey: [
          { required: true, trigger: 'blur' },
        ],
        sku: [
          { required: true, trigger: 'blur' },
        ],
        loc: [
          { required: true, trigger: 'blur', validator: this.loc },
        ],
      },
    }
  },
  computed: {
    inputConfig () {
      return [
        [
          {
            type: "input",
            label: this.$t('config.shipper'),
            props: "storerkey",
            disabled: !this.$parent.newFlag
          },
          {
            type: "input",
            label: this.$t('out.secondno'),
            props: "secondno",
          },
          {
            type: "table",
            label: this.$t('config.loc'),
            props: "loc",
            tableConfig: [
              {
                label: this.$t('config.loc'),
                prop: "loc",
                input: "input"
              },
              {
                label: this.$t('common.type'),
                prop: "locationtype",
                input: "select",
                options: this.getOptions("querycodeLkup/LOCTYPE")
              },
              {
                label: this.$t('config.area'),
                prop: "putawayzone",
                input: "select",
                options: this.getOptions("queryPutawayzoneDropDown")
              },
              {
                label: this.$t('config.locFlag'),
                prop: "locationflag",
                input: "select",
                options: this.getOptions("querycodeLkup/LOCFLAG")
              },
              {
                label: this.$t('config.locCategory'),
                prop: "locationcategory",
                input: "select",
                options: this.getOptions("querycodeLkup/LOCCATEGRY")
              },
              {
                label: this.$t('config.loseId'),
                prop: "loseid",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO")
              },
              {
                label: this.$t('in.comminglelot'),
                prop: "comminglelot",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO")
              },
              {
                label: this.$t('config.commingleSku'),
                prop: "comminglesku",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO")
              },
              {
                label: this.$t('config.capacity'),
                prop: "cubiccapacity",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO")
              }
            ],
            url: 'queryLoc/'
          }
        ],
        [
          {
            type: "input",
            label: this.$t('config.sku'),
            props: "sku",
            disabled: !this.$parent.newFlag
          },
          {
            type: "input",
            label: this.$t('out.firstno'),
            props: "firstno",
          }
        ],
      ]
    }
  },
  methods: {
    loc (rule, value, callback) {
      if(value){
        this.$api.get(`queryLocCount/${value}`).then(res => {
          
            if (parseInt(res.bean) > 0) {
              callback();
            } else {
              this.$message.error(this.$t('msg.msg23'));
              callback(new Error());
            }
        }).catch(e => {
          this.$message.error(e);
          callback(new Error());
        })
      }else{
        callback();
      }
    },
    setdata (data, id, close, listId) {
      if (id == 2 && listId == 0) {
        if (data.loseid == '是') {
          this.$message.error(this.$t('msg.msg65'))
        } else {
          this.inputData.loc = data.loc
        }
        close(false);
      }
    }
  },
  mounted () {

  },
  watch: {},
  components: {
    'v-details': details
  }
}
</script>

<style scoped>
</style>
